package controllers

import (
	"fawn/blog/consts"
	"fawn/blog/web/dao"
	"github.com/astaxie/beego"
	"go.uber.org/zap"
)

type ArticleController struct {
	beego.Controller
}

func (c *ArticleController) Details() {
	id, _ := c.GetInt("id")
	// 获取文章详情
	article, next, last, err := dao.ArticleDao.Info(dao.DB.Self, id)
	if err != nil {
		l.Error("mysql",
			zap.String("call", "dao.ArticleDao.List"),
			zap.String("error", err.Error()))
	} else {
		if article.Id > 0 {
			article.CreateTime = article.CreateAt.Format(consts.Layout)
			tags, err := dao.TagsDao.GetTagsInIds(dao.DB.Self, article.Seo)
			if err != nil {
				l.Error("mysql",
					zap.String("call", "dao.TagsDao.GetTagsInIds"),
					zap.String("error", err.Error()))
			}
			c.Data["tags"] = tags
		}
	}
	c.Data["article"] = article
	c.Data["next"] = next
	c.Data["last"] = last
	c.TplName = "details.html"
}
